<template>
  <div class="search">
    <div class="content">
      <input v-model="search" type="text" :placeholder="placeholder" :disabled="disabled" :readonly="disabled" />

      <div class="info">
        <slot />
      </div>
    </div>

    <div class="action" @click="onSearch">
      <img src="@/assets/icons/search.png" />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    placeholder: {
      type: String,
      default: '请输入搜索关键字'
    },

    disabled: {
      type: Boolean,
      default: false
    }
  },

  data() {
    return {
      search: ''
    }
  },

  methods: {
    onSearch() {
      const { $emit, search } = this
      $emit('search', search)
    }
  }
}
</script>

<style lang="less" scoped>
.search {
  background-color: #ffffff;
  padding: 10px 14.5px;
  display: flex;
  align-items: center;

  .content {
    position: relative;
    display: flex;
    flex: 1;

    .info {
      font-size: 12px;
      position: absolute;
      top: 50%;
      transform: translate(0, -50%);
      display: flex;
      align-items: center;
      left: 18px;
    }

    input {
      flex: 1;
      border: none;
      padding: 0 18px;
      height: 30px;
      background-color: #d9e7ff;
      border-radius: 15px;
      color: #2574ff;
      font-size: 12px;

      &::placeholder {
        color: rgba(37, 116, 255, 0.3);
      }
    }
  }

  .action {
    margin-left: 10px;
    display: flex;
    align-items: center;

    img {
      width: 20px;
    }
  }
}
</style>